package com.wisezone.demo0304;

import org.apache.commons.dbutils.ResultSetHandler;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class MyResultSetHander implements ResultSetHandler<List<Subject>> {

    @Override
    public List<Subject> handle(ResultSet resultSet) throws SQLException {
        Subject subject;
        List<Subject> subjects=null;
        if(resultSet!=null){
            subjects=new ArrayList<>();
            while (resultSet.next()){
                subject=new Subject();
                subject.setSubjectNo(resultSet.getInt(1));
                subject.setSubjectName(resultSet.getString(2));
                subject.setHours(resultSet.getInt(3));
                subject.setTermNo(resultSet.getInt(4));
                subjects.add(subject);
            }
        }
        return subjects;
    }
}

